import { listStaff,getStaff,createStaff,updateStaff,deleteStaff } from "@/pages/Setting/services/staff";

export default {
  namespace: "staff",

  state: {
    data: {
      list: [],
      pagination: {}
    }
  },

  effects: {
    *list({ payload }, { call, put }) {
      const response = yield call(listStaff, payload);
      yield put({
        type: "save",
        payload: response
      });
    },
    *get({ payload }, { call, put }) {
      const response = yield call(getStaff, payload);
      yield put({
        type: "save",
        payload: response
      });
    },
    *create({ payload, callback }, { call, put }) {
      const response = yield call(createStaff, payload);
      yield put({
        type: "save",
        payload: response
      });
      if (callback) callback();
    },
    *update({ payload, callback }, { call, put }) {
      const response = yield call(updateStaff, payload);
      yield put({
        type: "save",
        payload: response
      });
      if (callback) callback();
    },
    *delete({ payload, callback }, { call, put }) {
      const response = yield call(deleteStaff, payload);
      yield put({
        type: "save",
        payload: response
      });
      if (callback) callback();
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data
      };
    }
  }
};
